

<template>

  <div>
     
     <div v-if="list.length != 0">
          <div class="flex-row" style="margin: 0.6rem;margin-top: 1.2rem">
             <img style="width: 56.5%;height: 7.5rem" :src="list.cover_pic">
             <div class="flex" style="flex-direction: column;">
                <div @click="toTransfer" style="width: 6.2rem;font-size: 1rem; height: 2.2rem; background-color: #9e0b8a;line-height: 2.2rem;text-align: center;color: white;margin-left:2rem">转增好友</div>
                <div @click="toRecord" style="width: 6.2rem; font-size: 0.9rem; height: 2.2rem; line-height: 2.2rem;text-align: center;margin-left:2rem;margin-top: 0.6rem">领取记录>></div>
                <div @click="toTransferRecord" style="width: 6.2rem; font-size: 0.9rem; height: 2.2rem; line-height: 2.2rem;text-align: center;margin-left:2rem;margin-top: 0.6rem">转赠记录>></div>
             </div>

          </div>

           <div  class="flex-row" style="margin: 0.6rem;">
               <div style="width:27%; text-align: center; font-size: 0.92rem;">剩余：{{list.left_num}}张</div>
               <div style="width:39%; text-align: center;font-size: 0.92rem;">总数：{{list.send_num}}张</div>
               <div style="width:34%; text-align: center;font-size: 0.92rem">已赠送：{{list.send_num-list.left_num}}张</div>
           </div>
        
           <div style="width: 100%; height: 0.06rem; background-color: #e4e4e5; "></div>
           
           <div style="margin: 0.6rem;color: #746d60">
               <div class="card">名称：{{list.name}}</div>
               <div class="card">来源：{{list.remark}}</div>
               <div class="card">内容：{{list.desc}}</div>
               <div class="card">时间：{{list.addtime_memo}}</div>
               <div class="card" style="color: #910781;">已送出会员卡，好友24小时不领取将自动退回</div>
           </div>

           <div style="width: 100%; height: 0.01rem; background-color: #e4e4e5; "></div>
           <div style="width: 100%; height: 0.6rem; background-color: #e4e4e5; border-top:1px #cfcfcf solid;"></div>
     </div>
     
     <div v-if="list.length == 0" style="margin: 1rem auto; width: 55%; text-align: center; color:#7b7a7a ">你没有可以转赠的会员卡！</div>



  </div>

</template>

<script>
import { base64} from 'vux'

export default {

  components: {         
            base64
		},
  data () {
    return {
       
      none:true,
      access_token:'',
      list:''
    
    }
  },
  methods:{
     
    //获取首页详情
    getDetail(){
    	
	    this.$store.commit('updateLoadingStatus',true);
	    	
	    this.$http.get(this.$store.state.api + 'index/award-list&access_token=' + this.access_token)
	    .then((response) => {
	    		
	    console.log(response)
			
			if(response.body.code == 0) {
				
				this.list = response.body.data[0]
				
				console.log(this.list)
				
			} else if(response.body.code == 1){
				
				
			}
			
		    this.$store.commit('updateLoadingStatus',false);
		    
		}, (response) => {
	         
	         
		});
    },
    
    //转赠好友
    toTransfer(){
    	
    	var id = this.list.id
    	
    	this.$router.push({ path: '/transfer',name:'transfer',params:{id:id}});
    	
    },
    
    
    //领取记录
    toRecord(){
    	
    	var id = this.list.id
    	
    	this.$router.push({ path: '/classList',name:'classList',params:{id:id}});
    	
    },
    
    //转赠记录
    toTransferRecord(){
    	
    	var id = this.list.id
    	
    	this.$router.push({ path: '/transferRecord',name:'transferRecord',params:{id:id}});
    	
    },
    
    //获取地址栏信息
		getUrlStr(name){
	      let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)","i");
	      if(reg.test(window.location.href)){
	        return unescape(RegExp.$2.replace(/\+/g," "))
	      }
	      return undefined
	    },	
    
    
  },
  
  mounted() {
			
		  var access_token = this.getUrlStr('access_token');
           var parentId = this.getUrlStr('parent_id');
           
            if(parentId == undefined){
              parentId = 0;
           }
           
           var uid = this.getUrlStr('uid');
           
           console.log(parentId.toString().indexOf('?'));
           
           if(parentId.toString().indexOf('?') > 0){
           	 parentId = parentId.split('?')[0];
           }
           
           
//         var uid = this.getUrlStr('uid');

           var locurl = location.href;
           locurl = base64.encode(locurl.split('?')[0]);
//		   locurl = locurl.replace(/\//g, "@@");
           
           console.log('-1-'+access_token)
           console.log('-2-'+parentId)
           console.log('-4-'+uid)
          
          
       
           if(access_token != undefined){
         
              localStorage.setItem("access_token",access_token); 
              localStorage.setItem("parent_id",this.getUrlStr('uid'));


           }
           
           console.log('-3-'+localStorage.getItem('access_token'));
           
            if(localStorage.getItem('access_token') != null){
         
              this.$root.registerjudge();
              this.$root.getShare();
              
            }else{
            	
            	console.log(222);
        	  this.$root.gotoWechat(locurl,parentId);
            }
           
       
         
    	   this.access_token = localStorage.getItem('access_token');
		
		
		  this.getDetail();
			
	},


}



</script>


<style lang="less" scoped>
  
   .card{
      font-size: 0.9rem
   }

</style>
